package PIPL::System::FilesystemTest;

use strict;

use base 'Test::Unit::TestCase';

use PIPL::System::Filesystem;


sub new {
    my $self = shift()->SUPER::new(@_);
    return $self;
}

sub test_PIPL_System_Filesystem_new {
    my $self = shift;
    my $obj1 = PIPL::System::Filesystem->new;
    $self->assert_not_null($obj1);
    $self->assert($obj1->isa('PIPL::System::Filesystem'));
    my $obj2 = $obj1->new;
    $self->assert_not_null($obj2);
    $self->assert($obj2->isa('PIPL::System::Filesystem'));
}

sub test_PIPL_System_Filesystem_instance {
    my $self = shift;
    PIPL::System::Filesystem->destroy;
    my $obj1 = PIPL::System::Filesystem->instance;
    my $obj2 = PIPL::System::Filesystem->instance;
    $self->assert_not_null($obj1);
    $self->assert_not_null($obj2);
    $self->assert($obj1->isa('PIPL::System::Filesystem'));
    $self->assert($obj2->isa('PIPL::System::Filesystem'));
    $self->assert_equals($obj1, $obj2);
}

sub test_PIPL_System_Filesystem_Self_Win32 {
    my $self = shift;

    # set up
    my $orig_Self = $PIPL::System::Config::Self;
    $PIPL::System::Config::Self = {'osname'=>'MSWin32'};
    PIPL::System::Filesystem->destroy;
    my $obj1 = PIPL::System::Filesystem->instance;
    $self->assert_not_null($obj1);

    # main
    $self->assert_not_null($PIPL::System::Filesystem::Self->{spec});
    $self->assert_equals('Win32', $PIPL::System::Filesystem::Self->{spec});
    $self->assert($PIPL::System::Filesystem::Self->{is_Win32});
    $self->assert(!$PIPL::System::Filesystem::Self->{is_Unix});
    
    # tear down
    $PIPL::System::Config::Self = $orig_Self;
    PIPL::System::Filesystem->destroy;
    my $obj2 = PIPL::System::Filesystem->instance;
    $self->assert_not_null($obj2);
}

sub test_PIPL_System_Filesystem_Self_Unix {
    my $self = shift;

    # set up
    my $orig_Self = $PIPL::System::Config::Self;
    $PIPL::System::Config::Self = {'osname'=>'linux'};
    PIPL::System::Filesystem->destroy;
    my $obj1 = PIPL::System::Filesystem->instance;
    $self->assert_not_null($obj1);

    # main
    $self->assert_not_null($PIPL::System::Filesystem::Self->{spec});
    $self->assert_equals('Unix', $PIPL::System::Filesystem::Self->{spec});
    $self->assert($PIPL::System::Filesystem::Self->{is_Unix});
    $self->assert(!$PIPL::System::Filesystem::Self->{is_Win32});

    # tear down    
    $PIPL::System::Config::Self = $orig_Self;
    PIPL::System::Filesystem->destroy;
    my $obj2 = PIPL::System::Filesystem->instance;
    $self->assert_not_null($obj2);
}

1;
